#delimit ;
clear all;
set more off;
pause on;

/**************************************************************************************************/
/* ABOUT THIS FILE */
/**************************************************************************************************/
/*
PURPOSE
This file contains the coding of posters from Islamic party candidates.
They competed in Indonesia's legislative elections in 2009.
Drawing on the coded visual content of each poster and machine coding text transcriptions using dictionaries,
this file classifies a poster as having:
  A nationalist appeal and/or
  An Islamic appeal
*/

/**************************************************************************************************/

use "dta/appeals.dta";

/**************************************************************************************************/
/* RELIGIOUS CLOTHING */
/**************************************************************************************************/

/* There is only Islamic and Christian clothing elements in the posters. */

gen jilbab = 0;
replace jilbab = 1 if hd == "jilbab large";
replace jilbab = 1 if hd == "jilbab reg";
replace jilbab = 1 if hd == "selenda";

gen islam_cl = 0;
replace islam_cl = 1 if jilbab == 1;
replace islam_cl = 1 if hd=="peci design islamic";
replace islam_cl = 1 if hd=="skullcap";
replace islam_cl = 1 if hd=="turban";
replace islam_cl = 1 if clothing=="islamic";
replace islam_cl = 1 if cloth_acc=="islamic";

gen islam_cl_nocountjil = islam_cl;
replace islam_cl_nocountjil = 0 if jilbab == 1;

/**************************************************************************************************/
/* RELIGIOUS IMAGERY */
/**************************************************************************************************/

gen islam_im = 0;
replace islam_im = 1 if (regexm(imagery, "islam"));
replace islam_im = 1 if (regexm(imagery, "islamic"));
replace islam_im = 1 if (regexm(imagery, "mecca"));
replace islam_im = 1 if (regexm(imagery, "mosque"));
replace islam_im = 1 if (regexm(elites, "religion-islam"));
replace islam_im = 1 if (regexm(supporter_id, "religious-islam"));

/**************************************************************************************************/
/* RELIGIOUS TEXT */
/**************************************************************************************************/

replace verbal_appeals=lower(verbal_appeals);

/* Cut out Punctuation */
replace verbal_appeals = subinstr(verbal_appeals, "x-none", "",.);
replace verbal_appeals = subinstr(verbal_appeals, "'", "",.);
replace verbal_appeals = subinstr(verbal_appeals, "!", "",.);
replace verbal_appeals = subinstr(verbal_appeals, ".", " . ",.);
replace verbal_appeals = subinstr(verbal_appeals, "-", " - ",.);
replace verbal_appeals = subinstr(verbal_appeals, "?", " ? ",.);
replace verbal_appeals = subinstr(verbal_appeals, ",", " , ",.);
replace verbal_appeals = subinstr(verbal_appeals, ":", " : ",.);
replace verbal_appeals = subinstr(verbal_appeals, ";", " ; ",.);
replace verbal_appeals = subinstr(verbal_appeals, "(", "( ",.);
replace verbal_appeals = subinstr(verbal_appeals, ")", " )",.);

/* Invoking Islam */
local religion_islam
islam
allah
masjid
mesjid
ahhal
muslimah
muslimat
kabah
kaba
shariah
syaria
syariat
akbar
hadith
ustadz
assalamu
alhamdullilah
allahuakbar
alwasliyah
arabic
haji
syawal
imam
insyaallah
insyalloh
kyai
muhammadiya
muharam
muharram
muslim
muslimin
persis
qur'an
sholat
shalat
shaleh
shariat
shariah
syekh
taqwa
ulama
ustadz
ramadhan
;

gen islam_tx = 0;
foreach keyword in `religion_islam'{;
replace islam_tx = 1 if (regexm(verbal_appeals, " `keyword' "));
replace islam_tx = 1 if (regexm(verbal_appeals, "^`keyword' "));
replace islam_tx = 1 if (regexm(verbal_appeals, " `keyword'$"));
replace islam_tx = 1 if (regexm(verbal_appeals, "^`keyword'$"));
};
replace islam_tx = 1  if (regexm(verbal_appeals, "idul fitri"));
replace islam_tx = 1  if (regexm(verbal_appeals, "babi ilegal"));
replace islam_tx = 1  if (regexm(foreign_lang, "arabic"));

gen arabic = 0;
replace arabic = 1 if (regexm(foreign_lang, "arabic"));

/**************************************************************************************************/
/* NATIONALISM  IMAGERY */
/**************************************************************************************************/

gen nat_im = 0;
replace nat_im = 1 if (regexm(imagery, "indonesian_map"));
replace nat_im = 1 if (regexm(imagery, "national"));
replace nat_im = 1 if (regexm(imagery, "garuda"));
replace nat_im = 1 if (regexm(elites, "nationalism"));
replace nat_im = 1 if (regexm(supporter_id, "nationalism"));
replace nat_im = 1 if flag=="yes";

/**************************************************************************************************/
/* NATIONALIST TEXT */
/**************************************************************************************************/

local nation
nasionalis
indonesia
negeri
negara
motherland
pahlawan nasional
garuda;

gen nat_tx = 0;
foreach keyword in `nation'{;
replace nat_tx = 1 if (regexm(verbal_appeals, " `keyword' "));
replace nat_tx = 1 if (regexm(verbal_appeals, "^`keyword' "));
replace nat_tx = 1 if (regexm(verbal_appeals, " `keyword'$"));
replace nat_tx = 1 if (regexm(verbal_appeals, "^`keyword'$"));
};
replace nat_tx = 1 if (regexm(verbal_appeals, "kain tradisional"));

/**************************************************************************************************/
/* DEPENDENT VARIABLES */
/**************************************************************************************************/

/* Exclusive Islamic Appeal */
gen islam_pos = 0;
replace islam_pos = 1 if islam_cl == 1;
replace islam_pos = 1 if islam_im == 1;
replace islam_pos = 1 if islam_tx == 1;

gen islam_pos_nocountjil = islam_pos;
replace islam_pos_nocountjil = 0 if jilbab == 1;

/* Nationalist Appeals */
gen nat_pos = 0;
replace nat_pos = 1 if nat_im == 1;
replace nat_pos = 1 if nat_tx == 1;

/**************************************************************************************************/
/* ORDER, KEEP, & SAVE */
/**************************************************************************************************/

/* List of Vars to Keep */
local vars
can_id region // ID vars
islam_pos nat_pos islam_pos_nocountjil // DVs
election prov_no gender party con; // Other Vars

order `vars';
keep `vars';
sort region;

/* Show Output */
sum;
list in 1/2;

save "dta/appeals.dta", replace;

/**************************************************************************************************/
/* END */
/**************************************************************************************************/
